package com.captcha.model;



public class ResponseData<T> {

    public static final String SUCCESS = "0";
    public static final String FAIL = "9999";   // 通用错误码
    public static final String NOT_ROLE = "200"; // 没有权限
    public static final String NOT_LOGIN = "400"; // 未登陆错误
    public static final String NOT_WORKING = "600"; // 非工作时间
    public static final String FILE_UPLOAD_ERROR = "700"; // 文件上传错误
    public static final String FILE_UPLOAD_TOMAX = "800"; // 文件上传文件过大


    private String code;

    private String msg;

    private T data;

    public static ResponseData success(){
        return success("");
    }

    public static <T> ResponseData success(T data){
        ResponseData<T> result = new ResponseData<>();
        result.setCode(SUCCESS);
        result.setMsg("ok");
        result.setData(data);
        return result;
    }

    public static ResponseData<Object> error(String msg){
        ResponseData<Object> result = new ResponseData<>();
        result.setCode(FAIL);
        result.setMsg(msg);
        return result;
    }

    public static ResponseData notLogin(){
        ResponseData result = new ResponseData<>();
        result.setCode(NOT_LOGIN);
        result.setMsg("请先登录");
        return result;
    }

    public static ResponseData noAuth(){
        ResponseData result = new ResponseData<>();
        result.setCode(NOT_ROLE);
        result.setMsg("您没有权限");
        return result;
    }

    public static ResponseData error(String code, String msg){
        ResponseData result = new ResponseData<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public String getCode() {
        return code;
    }

    private void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    private void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    private void setData(T data) {
        this.data = data;
    }
}
